package demo02;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

//迭代器
public class test_1 {
    public static void main(String[] args) {
        Collection<String> list=new ArrayList<>();
        list.add("帅哥不帅");
        list.add("女人才爱");
        list.add("丑男帅了");
        list.add("更有人爱");
        //第一步获取一个迭代器
        Iterator<String> it=list.iterator();
     /*  //第二步使用Hasnext方法
        boolean b = it.hasNext();
        System.out.println(b);
        //第三步使用next()方法将里面的元素取出来
        String s = it.next();
        System.out.println(s);
        String s1 = it.next();
        System.out.println(s1);
        String s2 = it.next();
        System.out.println(s2);
        String s3 = it.next();
        System.out.println(s3);*/
     while (it.hasNext()){
         String s = it.next();
         System.out.print(s+" ");
     }

        try{
            String s = "hello";
            String sub = s.substring(0);
            System.out.println(sub);
            s = null;
        }catch(NullPointerException e){
            System.out.println("空指针异常");
        }
        System.out.println(1/0);
    }
}
